package com.finger.forest;

import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.finger.forest.adapter.CarAdapter;
import com.finger.forest.adapter.GPSAdapter;
import com.finger.forest.base.BaseActivity;
import com.finger.forest.base.BaseView;
import com.finger.forest.base.CommonKey;
import com.finger.forest.base.ResponseTag;
import com.finger.forest.http.presenter.RegisterPresenter;
import com.finger.forest.model.CarInfoModel;
import com.finger.forest.model.GpsEquipmentModel;
import com.finger.forest.utils.ClickUtils;
import com.finger.forest.utils.encode.PrefsUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 设备管理
 */
public class EquipmentManagerActivity extends BaseActivity<RegisterPresenter> implements BaseView {

    /**
     * 返回
     */
    @BindView(R.id.btn_back)
    ImageView backIv;

    /**
     * GPS设备
     */
    @BindView(R.id.tv_nav_road)
    TextView navRoadTv;

    /**
     * 车辆设备
     */
    @BindView(R.id.tv_nav_fire)
    TextView navFireTv;

    /**
     * 列表
     */
    @BindView(R.id.listView_equipment)
    ListView equipmentListView;

    Map<String, Object> maps = new HashMap<>();

    @Override
    protected int setView() {
        return R.layout.activity_equipment_manager;
    }

    @Override
    protected void receiveData() {

    }

    @Override
    protected void initializeView() {
        String userId = PrefsUtil.getString(this, CommonKey.USER_ID);
        maps.put("id",userId);
        //查询GPS设备
        presenter.queryGPSList(maps);
    }

    @Override
    protected void loadDataFromServer() {

    }

    private void reseNavColor() {
        navRoadTv.setTextColor(getResources().getColor(R.color.black));
        navFireTv.setTextColor(getResources().getColor(R.color.black));
    }

    @OnClick({R.id.btn_back, R.id.tv_nav_road, R.id.tv_nav_fire })
    public void onClick(View v) {
        if (ClickUtils.isFastClick()) { //防止重复点击
            switch (v.getId()) {

                //返回
                case R.id.btn_back:
                    finish();
                    break;

                case R.id.tv_nav_road:
                    //查询GPS设备
                    presenter.queryGPSList(maps);
                    break;

                case R.id.tv_nav_fire:
                    //查询车辆设备
                    presenter.queryCarList(maps);
                    break;

                default:
                    break;
            }
        }
    }

    @Override
    public void onSuccess(Object model, int tag, String msg) {

        switch (tag) {

            //初始化GPS设备列表
            case ResponseTag.QUERY_GPS_LIST:
                //高亮修改
                reseNavColor();
                navRoadTv.setTextColor(getResources().getColor(R.color.colorBlue));

                //更新数据
                List<GpsEquipmentModel> gpsList = (List<GpsEquipmentModel>) model;
                GPSAdapter gpsAdapter = new GPSAdapter(EquipmentManagerActivity.this, gpsList);
                equipmentListView.setAdapter(gpsAdapter);
                break;

            //初始化车辆设备列表
            case ResponseTag.QUERY_CAR_LIST:
                //高亮修改
                reseNavColor();
                navFireTv.setTextColor(getResources().getColor(R.color.colorBlue));

                //更新数据
                List<CarInfoModel> carList = (List<CarInfoModel>) model;
                CarAdapter carAdapter = new CarAdapter(EquipmentManagerActivity.this, carList);
                equipmentListView.setAdapter(carAdapter);
                break;

            default:
                break;
        }
    }

    @Override
    public void onError(int errcode, int tag, String message) {

    }
}
